package com.webservice.xmloper.commonDataManager;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class HouseIdConvertor implements Converter{

	public void marshal(Object source, HierarchicalStreamWriter writer,
			MarshallingContext context) {
		HouseId houseId = null;
		if(source != null ){
			houseId = (HouseId) source;
		}
		if(houseId != null && houseId.getHouseId() != null){
			writer.setValue(houseId.getHouseId());
		}else{
			writer.setValue("");
		}
	}

	public Object unmarshal(HierarchicalStreamReader reader,
			UnmarshallingContext context) {
		
		HouseId houseId = new HouseId();
		String houseID = reader.getValue();
		houseId.setHouseId(houseID);
		
        return houseId;
	}

	public boolean canConvert(Class type) {
		return type.equals(HouseId.class);
	}
	
}
